<?php
/**
 * the Firebug integrates Digitalus with firebug so you can profile and log
 * messages directly to firebug
 *
 * the base application loads the firephp logger as a resource
 * you can turn this on / off in the main application.ini file. simply
 * register the resource in the environments where it is appropriate:
 *
 * @example resources.firephp = true
 * 
 */
class Dig_Service_Firebug
{
    const PROFILER = 'dig_firebug_profile';

    /**
     * Adds a point to the profiler
     * 
     * This is an application profiler, as opposed to the Zend Db profiler, which is also enabled
     *
     * @example Dig_Service_Firebug::profile('Registering module configuration');
     *
     * @param string $message
     */
    public static function profile($message) {
        if(! self::enabled()) {
            return false;
        }
        
        $currentTime = microtime(true);
        if(Dig_Service_Core::hasParam(self::PROFILER)) {
            $elapsedTime = $currentTime - Dig_Service_Core::getParam(self::PROFILER);
            $message.= ' - elapsed time: ' . $elapsedTime;
        } else {
            $message .= ' - starting to profile application';
        }
        Dig_Service_Core::getInstance()->getParam(Dig_Resource_Firephp::FIRE_PHP)->log($message, Zend_Log::INFO);
        Dig_Service_Core::setParam(self::PROFILER, $currentTime);
    }

    /**
     * directly logs to firebug
     * use the Zend_Log constants for the types
     *
     * @param Dig_Service_Firebug::log('Could not find default item');
     * 
     * @param string $message
     * @param string $type
     */
    public static function log($message, $type = Zend_Log::INFO) {
        if(! self::enabled()) {
            return false;
        }
        Dig_Service_Core::getInstance()->getParam(Dig_Resource_Firephp::FIRE_PHP)->log($message, $type);
    }

    /**
     * checks to see if firebug is enabled
     *
     * @example $firebugEnabled = Dig_Service_Firebug::enabled();
     * 
     * @return bool
     */
    public static function enabled() {
        if(Dig_Service_Core::hasParam(Dig_Resource_Firephp::FIRE_PHP)) {
            return true;
        }
    }
}
?>
